/***************************************************************************
 *   Copyright (C) 2007 by saa   *
 *   root@saa   *
 ***************************************************************************/

#include <QtGui>

#include "mainwindow.h"
#include "newsessionform.h"
#include "routeserverform.h"
#include "linklistform.h"
#include "compilemode.h"
#include "database.h"


MainWindow::MainWindow() : QMainWindow()
{
    createActions();
    createMenus();

    statusBar()->showMessage(tr("Ready"));

    resize(400, 400);
    move(200, 200);
}

void MainWindow::closeEvent(QCloseEvent *event)
{ 
    event->accept();
}

 void MainWindow::startNewSession()
 {
    NewSessionForm * newSessionForm(new NewSessionForm(this));
    newSessionForm->exec();
    delete newSessionForm;
 }

void MainWindow::openRouteServerFile()
{
    QString fileName = QFileDialog::getOpenFileName( this, tr("Select routeserver database file"));
    if(fileName.isEmpty())
        return;

    RouteserverForm * routeServerForm = new RouteserverForm(fileName);
    routeServerForm->exec();
    delete routeServerForm;
}

void MainWindow::openLinkListFile()
{
    QStringList fileNames = QFileDialog::getOpenFileNames( this, tr("Select link database files"));
    if(fileNames.isEmpty())
        return;

    LinkListForm * linkListForm = new LinkListForm(fileNames);
    linkListForm->exec();
    delete linkListForm;
}

 void MainWindow::about()
{
    QMessageBox::about(this, tr("About ROUTETRACE"),
                       tr("The <b>ROUTETRACE</b> application building "
                               "Internet topology. "
                               "By Skorodumov Alex. 2350266@mgail.com"));
}

 void MainWindow::createActions()
{
    startNewSessionAct = new QAction(tr("Start &new session"), this);
    startNewSessionAct->setShortcut(tr("Ctrl+N"));
    startNewSessionAct->setStatusTip(tr("Statrt new session"));
    connect(startNewSessionAct, SIGNAL(triggered()), this, SLOT(startNewSession()));

    openRouteServerFileAct = new QAction(tr("&Open an existing routeserver data file"), this);
    openRouteServerFileAct->setShortcut(tr("Ctrl+O"));
    openRouteServerFileAct->setStatusTip(tr("Open an existing routeserver data file"));
    connect(openRouteServerFileAct, SIGNAL(triggered()), this, SLOT(openRouteServerFile()));

    openLinkListFileAct = new QAction(tr("Open an existing &link data files"), this);
    openLinkListFileAct->setShortcut(tr("Ctrl+L"));
    openLinkListFileAct->setStatusTip(tr("Open an existing link data files"));
    connect(openLinkListFileAct, SIGNAL(triggered()), this, SLOT(openLinkListFile()));

    exitAct = new QAction(tr("E&xit"), this);
    exitAct->setShortcut(tr("Ctrl+Q"));
    exitAct->setStatusTip(tr("Exit the application"));
    connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));

    aboutAct = new QAction(tr("&About"), this);
    aboutAct->setStatusTip(tr("Show the application's About box"));
    connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
}

 void MainWindow::createMenus()
{
    fileMenu = menuBar()->addMenu(tr("&Routetrace"));
    fileMenu->addAction(startNewSessionAct);
    fileMenu->addAction(openRouteServerFileAct);
    fileMenu->addAction(openLinkListFileAct);
    fileMenu->addSeparator();
    fileMenu->addAction(exitAct);

    menuBar()->addSeparator();

    helpMenu = menuBar()->addMenu(tr("&About"));
    helpMenu->addAction(aboutAct);
}
